<!--
 * @Description: 
 * @Author: charles
 * @Date: 2020-11-03 14:05:02
 * @LastEditors: charles
 * @LastEditTime: 2021-08-01 14:07:59
-->
<template>
  <div class="artice">
    <!-- 返回上一页按钮 -->
    <div class="toUpBottom">
      <el-button @click="toGo()" type="success" icon="el-icon-arrow-left" circle></el-button>
    </div>

    <div class="wrapper">
      <div class="title">{{ article.title }}</div>
      <div class="timeUser">
        {{ fmtDate(article.publishTime) }}|{{ article.baseUser.realname }}
      </div>
      <div class="content" v-html="article.content"></div>
      <!-- 点赞功能 -->
      <div class="btn">
        <el-button
          @click="toThumpUp(article.id)"
          type="primary"
          plain
          icon="el-icon-thumb"
          >赞！</el-button
        >
      </div>
    </div>
  </div>
</template>

<script>
import { fmtDate } from "../filters/index";
import { get } from "../utils/request";
export default {
  data() {
    return {
      id: "",
      article: {},
    };
  },
  methods: {
    //
    fmtDate,

    // 返回上一页
    toGo(){
      this.$router.go(-1)
    },
    // 查询方法
    findArticleDetailById() {
      get("/index/article/findById?id=" + this.id).then((res) => {
        if (res.status == 200) {
          this.article = res.data;
        } else {
          this.$message({
            type: "error",
            message: res.message,
          });
        }
      });
    },

    // 点赞方法
    toThumpUp(id) {
      get("/index/article/thumbUp?id=" + id).then((res) => {
        if (res.status == 200) {
          this.$message({
            type: "success",
            message: res.message,
          });
        } else {
          this.$message({
            type: "error",
            message: res.message,
          });
        }
      });
    },
  },

  created() {
    this.id = this.$route.query.id;
    this.findArticleDetailById();
  },
};
</script>

<style lang="scss" scoped>
.wrapper {
  width: 1240px;
  padding: 1em;
  .title {
    text-align: center;
    color: #333;
    font-weight: 700;
    line-height: 3em;
    font-size: 20px;
  }
  .timeUser {
    text-align: center;
    line-height: 2em;
  }
  .btn {
    text-align: center;
  }
}
</style>